using System;
using System.Collections;
using UnityEngine;

namespace Utils
{
	public static class CanvasGroupUtils
	{
		public static IEnumerator Fade(this CanvasGroup canvasGroup, float initialAlpha, float finalAlpha, float totalTime, Action onFinish = null)
		{
			AnimationCurve fadeCurve = AnimationCurve.EaseInOut(0f, initialAlpha, 1f, finalAlpha);
			for (float time = 0f; time < totalTime; time += Time.deltaTime)
			{
				canvasGroup.alpha = fadeCurve.Evaluate(time / totalTime);
				yield return null;
			}
			canvasGroup.alpha = finalAlpha;
			onFinish.Fire();
		}
	}
}
